<template>
  <div class="article-detail-view">
    <!-- 页面标题 -->
    <div class="page-header">
      <h1 class="page-title">文章详情</h1>
      <p class="page-subtitle">深入了解文章内容</p>
    </div>

    <!-- 文章主体 -->
    <div v-if="article" class="article-container">
      <!-- 文章头部 -->
      <div class="article-header">
        <h2 class="article-title">{{ article.title }}</h2>
        <div class="article-meta">
          <div class="author-info">
            <img v-if="article.avatar" :src="article.avatar" alt="作者头像" class="author-avatar">
            <div v-else class="avatar-placeholder">{{ article.username.charAt(0).toUpperCase() }}</div>
            <span class="author-name">{{ article.username }}</span>
          </div>
          <div class="publish-info">
              <span class="publish-time">{{ formatDate(article.createdAt) }}</span>
              <span class="view-count"><el-icon><View /></el-icon> {{ article.viewCount }} 阅读</span>
              <span class="like-count"><el-icon><Star /></el-icon> {{ article.likeCount }} 点赞</span>
              <span class="comment-count"><el-icon><ChatDotSquare /></el-icon> {{ article.commentCount }} 评论</span>
            </div>
        </div>
      </div>

      <!-- 文章分类和标签 -->
      <div class="article-tags">
        <el-tag type="primary" size="small" class="category-tag">{{ article.categoryName }}</el-tag>
        <el-tag v-for="tag in article.tags" :key="tag" size="small" class="article-tag">{{ tag }}</el-tag>
      </div>

      <!-- 文章内容 -->
      <div class="article-content" v-html="article.content"></div>

      <!-- 文章图片 -->
      <div v-if="article.images && article.images.length > 0" class="article-images">
        <div v-for="(image, index) in article.images" :key="index" class="image-wrapper">
          <img :src="image" :alt="`文章图片 ${index + 1}`" class="article-image" @click="handleImageClick(image)">
        </div>
      </div>

      <!-- 文章操作按钮 -->
      <div class="article-actions">
        <button class="action-btn like-btn" @click="handleLike">
          <el-icon><Star /></el-icon>
          <span>{{ isLiked ? '取消点赞' : '点赞' }}</span>
        </button>
        <button class="action-btn collect-btn" @click="handleCollect">
          <el-icon><Star /></el-icon>
          <span>{{ isCollected ? '取消收藏' : '收藏' }}</span>
        </button>
        <button class="action-btn share-btn" @click="handleShare">
          <el-icon><Share /></el-icon>
          <span>分享</span>
        </button>
      </div>

      <!-- 评论系统 -->
      <div class="comments-section">
        <h3 class="comments-title">评论 ({{ comments.length }})</h3>
        
        <!-- 评论输入框 -->
        <div class="comment-input-section">
          <div class="current-user-avatar">
            <div class="avatar-placeholder">{{ currentUser.charAt(0).toUpperCase() }}</div>
          </div>
          <div class="comment-input-wrapper">
            <el-input
              v-model="commentContent"
              type="textarea"
              placeholder="写下你的评论..."
              :rows="3"
              class="comment-textarea"
            />
            <div class="comment-actions">
              <el-button type="primary" @click="handleSubmitComment" :loading="submittingComment">
                发表评论
              </el-button>
            </div>
          </div>
        </div>

        <!-- 评论列表 -->
        <div class="comments-list" v-if="comments.length > 0">
          <div v-for="comment in comments" :key="comment.id" class="comment-item">
            <div class="comment-avatar">
              <img v-if="comment.avatar" :src="comment.avatar" alt="用户头像" class="avatar">
              <div v-else class="avatar-placeholder">{{ comment.username.charAt(0).toUpperCase() }}</div>
            </div>
            <div class="comment-content-wrapper">
              <div class="comment-header">
                <span class="comment-author">{{ comment.username }}</span>
                <span class="comment-time">{{ formatDate(comment.createdAt) }}</span>
              </div>
              <div class="comment-content">{{ comment.content }}</div>
              <div class="comment-footer">
                <button class="comment-action-btn" @click="handleCommentLike(comment.id)">
                  <el-icon><Star /></el-icon>
                  <span>{{ comment.likeCount }} 点赞</span>
                </button>
                <button class="comment-action-btn" @click="handleCommentReply(comment.id)">
                  <el-icon><ChatDotSquare /></el-icon>
                  <span>回复</span>
                </button>
                <button class="comment-action-btn" @click="handleCommentDelete(comment.id)">
                  <el-icon><Delete /></el-icon>
                  <span>删除</span>
                </button>
              </div>
            </div>
          </div>
        </div>

        <!-- 暂无评论 -->
        <div v-else class="no-comments">
          <el-empty description="暂无评论，快来发表第一条评论吧！"></el-empty>
        </div>
      </div>

      <!-- 返回按钮 -->
      <div class="back-container">
        <el-button type="default" @click="goBack">
          <el-icon><ArrowLeft /></el-icon>
          返回列表
        </el-button>
      </div>
    </div>

    <!-- 加载中 -->
    <div v-else-if="loading" class="loading-container">
      <el-loading text="加载中..." />
    </div>

    <!-- 文章不存在 -->
    <div v-else class="error-container">
      <el-empty description="文章不存在或已被删除"></el-empty>
      <el-button type="primary" @click="goBack">返回首页</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import type { Post, Comment } from '@/types/forum'
import { ElMessage } from 'element-plus'
import { View, Star, Share, ArrowLeft, ChatDotSquare, Delete } from '@element-plus/icons-vue'
import { getPostById, getPostComments, likePost, submitComment } from '@/api/forum'
import { addBrowseHistory } from '@/api/history'
import { addCollection, removeCollection } from '@/api/collection'

// 扩展Post接口，添加images属性
export interface ExtendedPost extends Post {
  images?: string[]
}

// 路由相关
const route = useRoute()
const router = useRouter()
const articleId = Number(route.params.id)

// 状态管理
// 暂时注释掉未使用的store，后续可能会用于API调用
// const forumStore = useForumStore()

// 文章数据
const article = ref<ExtendedPost | null>(null)
const loading = ref(true)
const isLiked = ref(false)
const isCollected = ref(false)

// 评论数据
const comments = ref<Comment[]>([])
const commentContent = ref('')
const submittingComment = ref(false)
const currentUser = ref('当前用户')

// 格式化日期
const formatDate = (dateString: string) => {
  const date = new Date(dateString)
  return new Intl.DateTimeFormat('zh-CN', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit'
  }).format(date)
}

// 加载文章详情
const loadArticleDetail = async () => {
  try {
    loading.value = true
    
    // 调用API获取文章详情
    const articleData = await getPostById(articleId)
    if (articleData) {
      article.value = articleData
      // 加载评论
      await loadComments()
      
      // 记录浏览历史
      const userId = localStorage.getItem('userId') || localStorage.getItem('user_id') || '1'
      console.log('开始记录文章浏览历史，用户ID:', userId, '文章数据:', article.value);
      if (userId && article.value) {
        // 创建浏览历史数据
        const historyData = {
          id: Date.now(),
          userId: Number(userId),
          contentType: 'FORUM', // 文章使用FORUM类型，因为文章实际上是论坛帖子
          contentId: Number(articleId),
          contentTitle: article.value.title,
          contentDescription: article.value.content?.substring(0, 100),
          contentUrl: `/article/${articleId}`,
          browseTime: new Date().toISOString(),
          createdAt: new Date().toISOString()
        };
        
        try {
          // 尝试调用API
          // 使用静态导入的addBrowseHistory
          await addBrowseHistory({
            userId: Number(userId),
            contentType: 'FORUM', // 文章使用FORUM类型
            contentId: Number(articleId),
            contentTitle: article.value.title,
            contentDescription: article.value.content?.substring(0, 100),
            contentUrl: `/article/${articleId}`
          })
          console.log('API文章浏览历史记录成功')
        } catch (historyError) {
          console.error('API记录文章浏览历史失败，使用本地存储:', historyError)
        }
        
        // 无论API是否成功，都保存到本地存储
        const historyKey = `browse_history_${userId}`;
        const existingHistory = JSON.parse(localStorage.getItem(historyKey) || '[]');
        
        // 检查是否已存在相同的浏览记录
        const existingIndex = existingHistory.findIndex((item: any) => 
          item.contentType === 'FORUM' && item.contentId === Number(articleId)
        );
        
        if (existingIndex !== -1) {
          // 如果已存在，更新浏览时间
          existingHistory[existingIndex].browseTime = new Date().toISOString();
        } else {
          // 如果不存在，添加新记录
          existingHistory.unshift(historyData);
        }
        
        // 只保留最近100条记录
        if (existingHistory.length > 100) {
          existingHistory.splice(100);
        }
        
        localStorage.setItem(historyKey, JSON.stringify(existingHistory));
        console.log('文章浏览历史已保存到本地存储，键名:', historyKey, '数据量:', existingHistory.length);
      } else {
        console.log('文章浏览历史记录条件不满足，用户ID:', userId, '文章数据存在:', !!article.value);
      }
    } else {
      ElMessage.error('文章不存在')
    }
  } catch (error) {
    console.error('加载文章详情失败:', error)
    ElMessage.error('加载文章详情失败')
    // 如果API调用失败，使用模拟数据作为后备
    loadMockData()
  } finally {
    loading.value = false
  }
}

// 加载评论
const loadComments = async () => {
  try {
    // 调用API获取评论
    const commentsData = await getPostComments(articleId, { page: 1, pageSize: 20 })
    if (commentsData && commentsData.items) {
      comments.value = commentsData.items
    }
  } catch (error) {
    console.error('加载评论失败:', error)
    // 如果API调用失败，使用模拟数据作为后备
    loadMockComments()
  }
}

// 加载模拟评论数据作为后备
const loadMockComments = async () => {
  try {
    // 模拟评论数据
    comments.value = [
      {
        id: 1,
        postId: articleId,
        content: '感谢分享，这些技巧很实用！',
        userId: 2,
        username: '备考小白',
        avatar: '/avatar/user1.jpg',
        likeCount: 5,
        isLiked: false,
        createdAt: '2024-05-16T09:15:00Z',
        updatedAt: '2024-05-16T09:15:00Z'
      },
      {
        id: 2,
        postId: articleId,
        content: '错题整理这一点很重要，我之前就是忽略了这一点，导致效率不高。',
        userId: 5,
        username: '努力备考中',
        avatar: '/avatar/user2.jpg',
        likeCount: 8,
        isLiked: false,
        createdAt: '2024-05-16T10:35:00Z',
        updatedAt: '2024-05-16T10:35:00Z'
      },
      {
        id: 3,
        postId: articleId,
        content: '请问老师有推荐的备考资料吗？',
        userId: 6,
        username: '新手小白',
        likeCount: 3,
        isLiked: false,
        createdAt: '2024-05-16T14:10:00Z',
        updatedAt: '2024-05-16T14:10:00Z'
      }
    ]
  } catch (error) {
    console.error('加载模拟评论失败:', error)
  }
}

// 加载模拟数据作为后备（当API失败时使用）
const loadMockData = async () => {
  try {
    await new Promise(resolve => setTimeout(resolve, 500)) // 模拟加载延迟
    
    // 模拟文章数据
    const mockArticles = [
      {
        id: 1,
        title: '公务员考试行测备考技巧分享',
        content: `<p>行测是公务员考试中的重要组成部分，很多考生在备考时感到困惑。下面我将分享一些行测备考的技巧：</p>\n\n<h3>一、合理规划时间</h3>\n<p>行测考试时间紧、题量大，合理规划时间至关重要。建议考生在备考时按照考试时间进行模拟练习，逐步提高做题速度。</p>\n\n<h3>二、掌握解题方法</h3>\n<p>行测的各个模块都有其特定的解题方法，比如数量关系中的代入排除法、资料分析中的速算技巧等。掌握这些方法可以大大提高解题效率。</p>\n\n<h3>三、注重错题整理</h3>\n<p>错题是最好的老师，建议考生建立错题本，定期回顾，避免在考试中重复犯错。</p>\n\n<h3>四、保持良好心态</h3>\n<p>备考过程中保持良好的心态非常重要，不要因为一次模拟考试的失利而气馁，要相信自己的能力。</p>`,
        categoryId: 1,
        categoryName: '行测',
        userId: 1,
        username: '张老师',
        avatar: '/avatar/teacher1.jpg',
        viewCount: 1254,
        likeCount: 89,
        commentCount: 23,
        tags: ['行测备考', '考试技巧', '公务员考试'],
        status: 'APPROVED' as const,
        isTop: false,
        isHot: true,
        isLiked: false,
        createdAt: '2024-05-15T10:30:00Z',
        updatedAt: '2024-05-15T10:30:00Z',
        images: ['/images/xingce1.jpg', '/images/xingce2.jpg']
      },
      {
        id: 2,
        title: '申论写作高分技巧详解',
        content: `<p>申论是公务员考试中的另一个重要科目，写作能力的高低直接影响考试成绩。以下是一些申论写作的高分技巧：</p>\n\n<h3>一、准确把握题意</h3>\n<p>在写作前，一定要仔细阅读题目要求，准确把握题意，避免偏离主题。</p>\n\n<h3>二、构建清晰结构</h3>\n<p>一篇好的申论文章应该有清晰的结构，通常包括引言、正文和结论三个部分。正文部分可以采用分论点的形式展开论述。</p>\n\n<h3>三、使用规范语言</h3>\n<p>申论写作要求使用规范、准确、简洁的语言，避免使用过于口语化的表达。同时，适当引用一些名言警句或政策文件，可以提升文章的说服力。</p>\n\n<h3>四、注重逻辑论证</h3>\n<p>在论述过程中，要注重逻辑的严密性，论点、论据和论证之间要有内在的联系。</p>\n\n<h3>五、多写多练</h3>\n<p>写作能力的提高需要不断地练习，建议考生每周至少写2-3篇申论文章，并请老师或同学进行点评。</p>`,
        categoryId: 2,
        categoryName: '申论',
        userId: 2,
        username: '李老师',
        avatar: '/avatar/teacher2.jpg',
        viewCount: 987,
        likeCount: 65,
        commentCount: 18,
        tags: ['申论写作', '高分技巧', '公务员考试'],
        status: 'APPROVED' as const,
        isTop: true,
        isHot: true,
        isLiked: false,
        createdAt: '2024-05-10T14:20:00Z',
        updatedAt: '2024-05-10T14:20:00Z',
        images: ['/images/shenlun1.jpg', '/images/shenlun2.jpg']
      },
      {
        id: 3,
        title: '面试准备全攻略',
        content: `<p>通过笔试后，面试是公务员考试的最后一道关卡。如何在面试中脱颖而出？以下是一些面试准备的全攻略：</p>\n\n<h3>一、了解面试形式</h3>\n<p>公务员面试通常采用结构化面试的形式，了解面试的流程和评分标准，有助于针对性地进行准备。</p>\n\n<h3>二、积累时政热点</h3>\n<p>面试题目往往与时政热点密切相关，考生在备考期间要关注时事政治，积累相关素材。</p>\n\n<h3>三、模拟面试练习</h3>\n<p>模拟面试是提高面试能力的有效方法。可以请家人或朋友扮演面试官，进行模拟面试练习，注意自己的仪表、语言表达和肢体语言。</p>\n\n<h3>四、保持自信</h3>\n<p>在面试过程中，保持自信非常重要。回答问题时要声音洪亮、条理清晰、逻辑严密。</p>\n\n<h3>五、注意细节</h3>\n<p>面试中的一些细节也很重要，比如提前到达面试地点、穿着得体、保持良好的精神状态等。</p>`,
        categoryId: 3,
        categoryName: '面试',
        userId: 3,
        username: '王老师',
        avatar: '/avatar/teacher3.jpg',
        viewCount: 1542,
        likeCount: 120,
        commentCount: 35,
        tags: ['面试准备', '公务员考试', '求职技巧'],
        status: 'APPROVED' as const,
        isTop: true,
        isHot: true,
        isLiked: false,
        createdAt: '2024-05-05T09:15:00Z',
        updatedAt: '2024-05-05T09:15:00Z',
        images: ['/images/interview1.jpg', '/images/interview2.jpg']
      }
    ]
    
    // 模拟评论数据
    const mockComments = [
      {
        id: 1,
        postId: articleId,
        content: '非常实用的备考技巧，谢谢分享！',
        userId: 4,
        username: '考生小明',
        avatar: '/avatar/user1.jpg',
        likeCount: 15,
        isLiked: false,
        createdAt: '2024-05-16T08:20:00Z',
        updatedAt: '2024-05-16T08:20:00Z'
      },
      {
        id: 2,
        postId: articleId,
        content: '错题整理这一点很重要，我之前就是忽略了这一点，导致效率不高。',
        userId: 5,
        username: '努力备考中',
        avatar: '/avatar/user2.jpg',
        likeCount: 8,
        isLiked: false,
        createdAt: '2024-05-16T10:35:00Z',
        updatedAt: '2024-05-16T10:35:00Z'
      },
      {
        id: 3,
        postId: articleId,
        content: '请问老师有推荐的备考资料吗？',
        userId: 6,
        username: '新手小白',
        likeCount: 3,
        isLiked: false,
        createdAt: '2024-05-16T14:10:00Z',
        updatedAt: '2024-05-16T14:10:00Z'
      }
    ]
    
    // 根据ID查找文章
    const articleData = mockArticles.find(article => article.id === articleId) || null
    
    // 如果找到文章，对数据进行处理以适应详情页展示
    if (articleData) {
      // 处理数据结构差异，确保用户能看到正确的内容
      article.value = articleData
      // 加载对应的评论数据
      comments.value = mockComments
    } else {
      article.value = null
      comments.value = []
    }
  } catch (error) {
    console.error('加载文章详情失败:', error)
    ElMessage.error('加载文章详情失败，请稍后重试')
  } finally {
    loading.value = false
  }
}

// 处理点赞
const handleLike = async () => {
  try {
    if (article.value) {
      await likePost(article.value.id)
      isLiked.value = !isLiked.value
      article.value.likeCount += isLiked.value ? 1 : -1
      ElMessage.success(isLiked.value ? '点赞成功' : '取消点赞')
    }
  } catch (error) {
    console.error('点赞失败:', error)
    ElMessage.error('操作失败，请重试')
  }
}


// 处理分享
const handleShare = () => {
  // 模拟分享功能
  navigator.clipboard.writeText(window.location.href).then(() => {
    ElMessage.success('链接已复制到剪贴板')
  }).catch(() => {
    ElMessage.error('复制失败，请手动复制链接')
  })
}

// 处理图片点击
const handleImageClick = (_imageUrl: string) => {
  // 这里可以实现图片预览功能
  ElMessage.info('图片预览功能待实现')
}

// 返回上一页
const goBack = () => {
  if (window.history.length > 1) {
    router.back()
  } else {
    router.push('/forum')
  }
}

// 提交评论
const handleSubmitComment = async () => {
  if (!commentContent.value.trim()) {
    ElMessage.warning('评论内容不能为空')
    return
  }
  
  try {
    submittingComment.value = true
    
    // 调用API提交评论
    const newComment = await submitComment(articleId, commentContent.value)
    if (newComment) {
      // 添加到评论列表
      comments.value.unshift(newComment)
      
      // 更新文章评论数
      if (article.value) {
        article.value.commentCount = (article.value.commentCount || 0) + 1
      }
      
      // 清空输入框
      commentContent.value = ''
      
      ElMessage.success('评论发表成功')
    }
  } catch (error) {
    console.error('发表评论失败:', error)
    ElMessage.error('发表评论失败，请稍后重试')
  } finally {
    submittingComment.value = false
  }
}

// 评论点赞
const handleCommentLike = (commentId: number) => {
  const comment = comments.value.find(c => c.id === commentId)
  if (comment) {
    // 切换点赞状态
    const wasLiked = comment.isLiked || false
    comment.isLiked = !wasLiked
    comment.likeCount += wasLiked ? -1 : 1
    ElMessage.success(wasLiked ? '取消点赞成功' : '点赞成功')
  }
}

// 回复评论
const handleCommentReply = (commentId: number) => {
  const comment = comments.value.find(c => c.id === commentId)
  if (comment) {
    commentContent.value = `回复 @${comment.username}: `
    // 聚焦到输入框
    setTimeout(() => {
      const textarea = document.querySelector('.comment-textarea textarea')
      if (textarea) {
        (textarea as HTMLTextAreaElement).focus()
      }
    }, 0)
  }
}

// 删除评论
const handleCommentDelete = (commentId: number) => {
  try {
    // 从评论列表中移除
    comments.value = comments.value.filter(comment => comment.id !== commentId)
    
    // 更新文章评论数
    if (article.value) {
      article.value.commentCount = Math.max(0, (article.value.commentCount || 0) - 1)
    }
    
    ElMessage.success('评论删除成功')
  } catch (error) {
    console.error('删除评论失败:', error)
    ElMessage.error('删除评论失败，请稍后重试')
  }
}

// 收藏功能
const handleCollect = async () => {
  if (!article.value) return;
  
  try {
    const userId = localStorage.getItem('userId') || localStorage.getItem('user_id') || '1';
    
    if (isCollected.value) {
      // 取消收藏
      try {
        // 使用静态导入的removeCollection
        await removeCollection(Number(userId), 'FORUM', Number(article.value.id));
        isCollected.value = false;
        ElMessage.success('取消收藏成功');
      } catch (error) {
        console.error('取消收藏失败:', error);
        ElMessage.error('取消收藏失败');
      }
    } else {
      // 添加收藏
      try {
        // 使用静态导入的addCollection
        await addCollection({
          userId: Number(userId),
          contentType: 'FORUM',
          contentId: Number(article.value.id),
          contentTitle: article.value.title,
          contentDescription: article.value.content?.substring(0, 100),
          contentUrl: `/article/${article.value.id}`
        });
        isCollected.value = true;
        ElMessage.success('收藏成功');
      } catch (error) {
        console.error('收藏失败:', error);
        // 如果API失败，至少在前端记录
        const collectionKey = `collections_${userId}`;
        const existingCollections = JSON.parse(localStorage.getItem(collectionKey) || '[]');
        const newCollectionItem = {
          id: Date.now(),
          userId: Number(userId),
          contentType: 'FORUM', // 文章使用FORUM类型，保持一致性
          contentId: Number(article.value.id),
          contentTitle: article.value.title,
          contentDescription: article.value.content?.substring(0, 100),
          contentUrl: `/article/${article.value.id}`,
          collectTime: new Date().toISOString(),
          createdAt: new Date().toISOString()
        };
        existingCollections.unshift(newCollectionItem);
        // 只保留最近100条记录
        if (existingCollections.length > 100) {
          existingCollections.splice(100);
        }
        localStorage.setItem(collectionKey, JSON.stringify(existingCollections));
        isCollected.value = true;
        ElMessage.success('收藏成功（已保存到本地）');
      }
    }
  } catch (error) {
    console.error('收藏操作失败:', error);
    ElMessage.error('操作失败');
  }
};

// 组件挂载时加载数据
onMounted(() => {
  loadArticleDetail()
})
</script>

<style scoped>
.article-detail-view {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.page-header {
  text-align: center;
  margin-bottom: 30px;
}

.page-title {
  font-size: 28px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 10px;
}

.page-subtitle {
  font-size: 16px;
  color: #606266;
}

.article-container {
  background-color: #fff;
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.article-header {
  margin-bottom: 20px;
}

.article-title {
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 15px;
  line-height: 1.4;
}

.article-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.author-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #409eff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.author-name {
  font-size: 16px;
  color: #303133;
}

.publish-info {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 14px;
  color: #606266;
}

.article-tags {
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.article-content {
  font-size: 16px;
  line-height: 1.8;
  color: #303133;
  margin-bottom: 30px;
}

.article-content h3 {
  font-size: 20px;
  margin-top: 25px;
  margin-bottom: 15px;
  color: #303133;
}

.article-content p {
  margin-bottom: 15px;
}

.article-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.image-wrapper {
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);
}

.article-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  transition: transform 0.3s ease;
  cursor: pointer;
}

.article-image:hover {
  transform: scale(1.05);
}

.article-actions {
  display: flex;
  gap: 15px;
  margin-bottom: 30px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border: 1px solid #dcdfe6;
  background-color: #fff;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  color: #606266;
}

.action-btn:hover {
  color: #409eff;
  border-color: #409eff;
}

.back-container {
  text-align: center;
  margin-top: 30px;
}

.loading-container,
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .article-detail-view {
    padding: 10px;
  }
  
  .article-container {
    padding: 20px;
  }
  
  .article-title {
    font-size: 20px;
  }
  
  .article-meta {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .publish-info {
    gap: 10px;
  }
  
  .article-images {
    grid-template-columns: 1fr;
  }
  
  .article-actions {
    flex-wrap: wrap;
  }
}
  .comments-section {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 1px solid #e4e7ed;
  }

  .comments-title {
    font-size: 20px;
    font-weight: 600;
    color: #303133;
    margin-bottom: 20px;
  }

  .comment-input-section {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
  }

  .current-user-avatar {
    flex-shrink: 0;
  }

  .comment-input-wrapper {
    flex: 1;
  }

  .comment-textarea {
    margin-bottom: 10px;
  }

  .comment-actions {
    text-align: right;
  }

  .comments-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .comment-item {
    display: flex;
    gap: 15px;
  }

  .comment-avatar {
    flex-shrink: 0;
  }

  .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
  }

  .comment-content-wrapper {
    flex: 1;
  }

  .comment-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 8px;
  }

  .comment-author {
    font-size: 15px;
    font-weight: 500;
    color: #303133;
  }

  .comment-time {
    font-size: 13px;
    color: #909399;
  }

  .comment-content {
    font-size: 14px;
    line-height: 1.6;
    color: #303133;
    margin-bottom: 10px;
    word-break: break-word;
  }

  .comment-footer {
    display: flex;
    gap: 20px;
  }

  .comment-action-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: #909399;
    transition: color 0.3s ease;
  }

  .comment-action-btn:hover {
    color: #409eff;
  }

  .no-comments {
    padding: 40px 0;
    text-align: center;
  }

  /* 响应式设计 */
  @media (max-width: 768px) {
    .comments-section {
      margin-top: 30px;
      padding-top: 20px;
    }

    .comment-input-section {
      flex-direction: column;
      align-items: flex-start;
    }

    .current-user-avatar {
      align-self: flex-start;
    }
  }
</style>